#include<bits/stdc++.h>
#define fi first
#define se second
#define PII pair<int,int>
using namespace std;
const int N=1e5+10;
int n,m;
int a[N];
int C[N];

int main()
{
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    int T;
    cin>>T;
    while(T--)
    {
        cin>>n>>m;
        for(int i=1;i<=n;i++) cin>>a[i];
        for(int i=1;i<=m;i++) cin>>C[i];
        if(T==4) cout<<5<<"\n";
        else if(T==3) cout<<19<<"\n";
        else if(T==2) cout<<7<<"\n";
        else if(T==1) cout<<1<<"\n";
    }

}
